<template>
  <div class="contain">
    <!-- 搜索 -->
    <el-form :model="query" ref="queryForm" :inline="true" class="top-search" label-position="left">
      <el-form-item label="关键词" prop="enterpriseName">
        <el-input v-model="query.enterpriseName" placeholder="请输入" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList()">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作菜单 -->
    <div class="mid-action">
      <div>
        <!-- <el-button type="primary" size="mini" @click="creatItem('creat')">添加</el-button> -->
      </div>
    </div>
    <!-- 表格列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="公司名" align="center" prop="name" />
      <el-table-column label="行业" align="center" prop="industryInvolved" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="statusShow(scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList()"
    />
    <!-- 审核 -->
    <el-dialog title="审核" :visible.sync="statusFormShow">
      <el-form class="edit_form" :model="form" ref="form" label-width="100px" label-position="right">
        <el-form-item label="公司名">
          <el-input v-model="form.enterpriseName" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="企业照片">
          <el-image class="avatar" :src="form.companyPicture" :preview-src-list="[form.companyPicture]"></el-image>
        </el-form-item>
        <el-form-item label="企业简介">
          <el-input v-model="form.companyProfile" type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="位置周边">
          <el-input v-model="form.ambitus" type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="荣誉照片">
          <el-image class="avatar" v-for="(item,index) in form.honorCertification" :key="index" 
          :src="item" :preview-src-list="[item]"></el-image>
        </el-form-item>
        <el-form-item label="宣传视频">
          <video :src="form.publicityVideo" style="height:200px; width: 350px;" controls></video>
        </el-form-item>
        <el-form-item label="宣传册">
          <el-button type="primary" icon="el-icon-view" @click="openDocument(form.brochure)" v-if="form.brochure">查看</el-button>
        </el-form-item>
        <el-form-item label="审核结果">
          <el-radio-group v-model="form.check" size="small">
            <el-radio label="1" border>通过</el-radio>
            <el-radio label="2" border>拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="statusChange()">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getCompanyEditList, getCompanyEditInfo, updateCompanyEditStatus } from "@/api/eh-api";
export default {
  data() {
    return {
        //审核
        statusFormShow:false,
        form:{
          check: ''
        },
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 查询参数
        query: {
            pageNum: 1,
            pageSize: 10,
            enterpriseName: undefined,
        },
        list:[],
    };
  },
  created() {
    this.getList()
  },
  methods: {
    /**
     * 接口 - 获取列表
     */
    getList() {
      this.loading = true;
      getCompanyEditList(this.query).then(({ rows, total }) => {
        this.list = rows;
        this.total = parseInt(total);
        this.loading = false;
        this.ids = [];
      })
      .catch(() => {
        this.loading = false;
      });
    },

    /**
     * 事件 - 打开审核表单
     */
    statusShow:function(row){
        getCompanyEditInfo({
          id: row.id
        }).then( res => {
          if( res.code == 200 ){
            this.form = res.data
            this.form.honorCertification ? this.form.honorCertification = res.data.honorCertification.split(',') : ''
            this.form.enterpriseName = row.name
            this.form.id = row.id
            this.form.cardId = row.cardId
            this.statusFormShow = true
          }else{
            this.$message.error(res.msg);
          }
        })
    },

    /**
     * 接口 - 审核表单提交
     */
    statusChange:function(){
      // console.log(this.form)
      if(!this.form.check){
        this.$message.error('请选择审核状态');
        return
      }
      let form = {}
      form.homeId = this.form.id
      form.cardId = this.form.cardId
      form.check = this.form.check
      console.log(form)
      updateCompanyEditStatus(form).then( res => {
        if( res.code == 200 ){
          this.$message({
            message: '修改成功',
            type: 'success'
          });
          this.statusFormShow = false
          this.getList();
        }else{
          this.$message.error(res.msg);
        }
      })
    },

    /**
     * 打开文档 - 宣传手册
     */
    openDocument:function(url){
      window.open(url)
    },

    /**
     * 统一路由
     */
    route(row) {
      console.log(row)
      this.$router.push({ path: '/material/article/creat', query: { enterpriseId:row.id } })
    },

  },
};
</script>

<style lang="scss" scoped>
.mid-action {
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
  align-items: center;
  .total {
    background-color: rgba(65, 133, 244, 0.1);
    border: 1px solid rgba(65, 133, 244, 0.2);
    border-radius: 3px;
    font-size: 14px;
    min-height: 32px;
    line-height: 32px;
    padding: 0 12px;
    color: #606266;
  }
  .num {
    color: #00f;
  }
}
.thumbnail {
  width: 160px;
  height: 80px;
}
.input{
  width: 80%;
}

/**头像 */
.avatar-uploader /deep/.el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.avatar-uploader /deep/.el-upload:hover {
    border-color: #409EFF;
}
.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 128px;
    height: 128px;
    line-height: 128px;
    text-align: center;
}
.avatar {
    width: 128px;
    height: 128px;
    display: inline-block;
}
</style>
